#ifndef __GENERAL_H
#define __GENERAL_H
#include "stdtype.h"
#include "overload.h"

/* get the base by the property which contained inside */
#define container(addr, type, attr) ((type*)((mx_addr_t)addr - (mx_addr_t)(&((type*)0)->attr)))
/* get array length */
#define _len0(p0, p1, p2, p3, p4, p5, p6, p7) (sizeof(p0) / sizeof(p0[0]))  /* len(arr) */
#define _len1(p0, p1, p2, p3, p4, p5, p6, p7) (sizeof(p1) / sizeof(p0))     /* len(type, arr) */
#define len(...) OVERLOAD(_len, __VA_ARGS__)

/* delay (cpu cycles) */
void mx_delay (mx_usize_t lc);

#endif
